var DxfParser = require('../');
var fs = require('fs');
var path = require('path');

var DXF_FILE_PATH = path.join(__dirname, 'data', 'build.dxf');
var OUTPUT_FILE_NAME = "cad.json";

var fileStream = fs.createReadStream(DXF_FILE_PATH, { encoding: 'utf8' });

var parser = new DxfParser();

var layer_color = {}

parser.parseStream(fileStream, function(err, dxf) {
    if(err) return console.error(err.stack);
    //fs.writeFileSync(OUTPUT_FILE_NAME, JSON.stringify(dxf, null, 3));
    dxf.entities.map(function(e){
        if(e.color){
            if(!layer_color[e.layer]){
                layer_color[e.layer] = {}
            }
            
            if(!layer_color[e.layer][e.color]){
                layer_color[e.layer][e.color] = 0
            }
            layer_color[e.layer][e.color] ++
        }
        if(e.type){
            if(!layer_color[e.layer]){
                layer_color[e.layer] = {}
            }

            if(!layer_color[e.layer][e.type]){
                layer_color[e.layer][e.type] = 0
            }
            layer_color[e.layer][e.type] ++
        }
    })
   
    console.log(layer_color)
});